package com.eagledata.framework.web.service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.eagledata.project.system.dict.domain.DictData;
import com.eagledata.project.system.dict.service.IDictDataService;

/**
 * RuoYi首创 html调用 thymeleaf 实现字典读取
 * 
 * @author ruoyi
 */
@Component
public class DictService {
	@Autowired
	private IDictDataService dictDataService;

	/**
	 * 根据字典类型查询字典数据信息
	 * 
	 * @param dictType
	 *            字典类型
	 * @return 参数键值
	 */
	public List<DictData> selectDictData(String dictType) {
		return dictDataService.selectDictDataByType(dictType);
	}
	
	/**
	 * 根据字典类型查询字典数据信息
	 * @param dictType
	 * @return
	 */
	public Map<String, String> getDictData(String dictType){
		List<DictData> datas =selectDictData(dictType);
		if(null == datas || datas.size() <1) {
			return Collections.emptyMap();
		}
		Map<String, String> result = new HashMap<>();
		for (DictData dictData : datas) {
			result.put(dictData.getDictValue(), dictData.getDictLabel());
		}
		return result;
	}
}
